/* Author: Mark Mckillion
 * Student ID: B00540772
 * Date: 07/03/2012
 * Version 1.0.*/
package assignment3;

public class Incoming implements Runnable
{   /*Create a class that will use Runnable to override run. This will be used 
     *to create and run Threads with defined parameters.*/
    
    //Create the variables and objects that will be used within the Thread.
    private long time;
    private int amount;
    private BankAccount acc;
    private String type;
    
    /*Create a constructor that will accept the parameters needed to update and
     *output information.*/
    public Incoming(String string, long num1, int num2, BankAccount account)
    {   //Make the class variables equal the parameter variables.
        type = string;
        time = num1;
        amount = num2;
        acc = account;
    }
    
    @Override
    public void run()
    {   /*Use a try-catch block which will throw an Exception if the Thread
         *cannot be executed.*/
        try 
        {   while(true)
            {   /*while the Thread is valid deposit the amount required and 
                 *pause until 'time' has expired.*/
                acc.deposit(amount, type);   
                Thread.sleep(time);
            }
        } catch (InterruptedException ex) 
        {   //Stop the thread if not valid, no output required.
        }
    }
} // End of class Incoming